﻿using EFModel;
using IServices;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;
using Y2.Dao;

namespace Serives
{
    [Obsolete]
    public class Teconfig_file_third_kind: Iconfig_file_third_kind
    {
        private readonly MyDBContext he;

        public Teconfig_file_third_kind(MyDBContext he)
        {
            this.he = he;
        }

        Task<ResultInfo> Iconfig_file_third_kind.Index5(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.config_file_third_kind;
                var list = he.config_file_third_kind
                    .Select(e => new { e.ftk_id, e.first_kind_id, e.first_kind_name, e.second_kind_id, e.second_kind_name, e.third_kind_id, e.third_kind_is_retail, e.third_kind_name, e.third_kind_sale_id, e.config_file_second_kind, e.config_file_first_kind })
                    .OrderBy(q => q.ftk_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }

        Task<int> Iconfig_file_third_kind.Inser2(string first_kind_id, string first_kind_name, string second_kind_id, string second_kind_name, string third_kind_id, string third_kind_name, string third_kind_sale_id, string third_kind_is_retail)
        {
            return Task.Run(() => {
                string sql = $@"insert into [dbo].[config_file_third_kind]([first_kind_id], [first_kind_name], [second_kind_id], [second_kind_name], [third_kind_id], [third_kind_name], [third_kind_sale_id], [third_kind_is_retail])
                            values('{first_kind_id}','{first_kind_name}','{second_kind_id}','{second_kind_name}','{third_kind_id}','{third_kind_name}','{third_kind_sale_id}','{third_kind_is_retail}');";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_file_third_kind.Updat2(int ftk_id, string first_kind_id, string first_kind_name, string second_kind_id, string second_kind_name, string third_kind_id, string third_kind_name, string third_kind_sale_id, string third_kind_is_retail)
        {
            return Task.Run(() => {
                string sql = $@"update [dbo].[config_file_third_kind] set [first_kind_id]='{first_kind_id}', [first_kind_name]='{first_kind_name}', [second_kind_id]='{second_kind_id}', [second_kind_name]='{second_kind_name}', [third_kind_id]='{third_kind_id}', [third_kind_name]='{third_kind_name}', [third_kind_sale_id]='{third_kind_sale_id}', [third_kind_is_retail]='{third_kind_is_retail}'
                                        where [ftk_id]={ftk_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<int> Iconfig_file_third_kind.delt2(int ftk_id)
        {
            return Task.Run(() => {
                string sql = $@"delete from [dbo].[config_file_third_kind]
                            where [ftk_id]={ftk_id}";

                int i = he.Database.ExecuteSqlCommand(sql);
                return i;
            });
        }

        Task<string> Iconfig_file_third_kind.Inde2()
        {
            return Task.Run(() => {
                List<Typn> list = new List<Typn>();
                var io = he.config_file_first_kind;
                foreach (var item in io)
                {
                    Typn t = new Typn()
                    {
                        value = item.ffk_id,
                        label = item.first_kind_name,
                        children = he.config_file_second_kind.Where(e => e.first_kind_id == item.ffk_id).Select(s => new { value = s.fsk_id, label = s.second_kind_name })
                    };
                    list.Add(t);
                }
                return JsonConvert.SerializeObject(list);
            });
        }
    }
}
